import javax.swing.JOptionPane;
//import java.util.Scanner;
import java.util.Random;

public class Challenge6
//simple RPG
{
	public static int herohp = 20;
	public static int minionhp = 10;
	public static int bosshp = 20;
	public static String name = JOptionPane.showInputDialog("Enter your hero's name");
	
	public static void main(String[] args)
	{
		//Scanner input = new Scanner(System.in);
		Random randomNumberGenerator = new Random();
		
		JOptionPane.showMessageDialog(null, name + " walks into a forest and sees a vicious tiger.");
		if (herohp <= 0)
		{
			JOptionPane.showMessageDialog(null, name + " has died.  You lose.");
		}
		{
			while (minionhp > 0 && herohp <= 200)
			{
				
				String achoice = JOptionPane.showInputDialog("You can heal or you can attack.\n 1 to attack. \n 2 to heal.");
				switch (achoice)
				{
					case "1":
						int damage = randomNumberGenerator.nextInt(6);
						int cdamage = randomNumberGenerator.nextInt(4);
						JOptionPane.showMessageDialog(null, name + " hits the tiger for " + damage + " damage.");
						minionhp -= damage;
						JOptionPane.showMessageDialog(null, "The tiger strikes back for " + cdamage + " damage");
						herohp -= cdamage;
						showhp();
						if (herohp <= 0)
						{
							JOptionPane.showMessageDialog(null, name + " has died.  You lose.");
						}
						break;
					case "2":
						int heal = randomNumberGenerator.nextInt(6) + 2;
						int crdamage = randomNumberGenerator.nextInt(4);
						JOptionPane.showMessageDialog(null, name + " heals himself for " + heal + " HP.");
						herohp += heal;
						JOptionPane.showMessageDialog(null, "The tiger strikes back for " + crdamage + " damage");
						herohp -= crdamage;
						showhp();
						if (herohp <= 0)
						{
							JOptionPane.showMessageDialog(null, name + " has died.  You lose.");
						}
						break;
					default:
						JOptionPane.showMessageDialog(null, "You have typed an invalid command. " + name + " looses half of his current hp.");
						herohp -= (herohp / 2);
						if(herohp <= 0)
						{
							JOptionPane.showMessageDialog(null, name + " has died.  You lose.");
						}
				}
				if (minionhp <= 0)
				{
					JOptionPane.showMessageDialog(null, "You have killed the tiger!");
					JOptionPane.showMessageDialog(null, name + " levels up.");
					JOptionPane.showMessageDialog(null, name + "'s damage increased!");
					JOptionPane.showMessageDialog(null, name + " stumbles upon a dark cave and enters a battle with a demon.");
					while (bosshp > 0 && herohp <= 2000)
					{
						
						achoice = JOptionPane.showInputDialog("You can heal or you can attack.\n 1 to attack. \n 2 to heal.");
						switch (achoice)
						{
							case "1":
								int damage = randomNumberGenerator.nextInt(9);
								int cdamage = randomNumberGenerator.nextInt(8);
								JOptionPane.showMessageDialog(null, name + " hits the Demon for " + damage + " damage.");
								bosshp -= damage;
								JOptionPane.showMessageDialog(null, "The Demon strikes back for " + cdamage + " damage");
								herohp -= cdamage;
								showhp();
								if(herohp <= 0)
								{
									JOptionPane.showMessageDialog(null, name + " has died.  You lose.");
								}
								break;
							case "2":
								int heal = randomNumberGenerator.nextInt(9) + 2;
								int crdamage = randomNumberGenerator.nextInt(8);
								JOptionPane.showMessageDialog(null, name + " heals himself for " + heal + " HP.");
								herohp += heal;
								JOptionPane.showMessageDialog(null, "The Demon strikes back for " + crdamage + " damage");
								herohp -= crdamage;
								showhp();
								if(herohp <= 0)
								{
									JOptionPane.showMessageDialog(null, name + " has died.  You lose.");
								}
								break;
							default:
								JOptionPane.showMessageDialog(null, "You have typed an invalid command. " + name + " loses half of his current hp.");
								herohp -= (herohp / 2);
								if(herohp <= 0)
								{
									JOptionPane.showMessageDialog(null, name + " has died.  You lose.");
								}
								
								// one weird glitch, this happened to my game too: Occasionally I get a blank box instead of the text.
								// I like that you can heal or attack.
								// I also like being able to input my name.
						}
						if (bosshp <= 0)
						{
							JOptionPane.showMessageDialog(null, "You have killed the Demon!");
							JOptionPane.showMessageDialog(null, "You have won the game!");
						}
					}
					
				}
			}
		}
	}
	
	public static void showhp()
	{
		if (minionhp > 0)
		{
			JOptionPane.showMessageDialog(null, "=====================\n" + name + "'s HP: " + herohp + "\n Tiger HP: " + minionhp + "\n=====================");
		}
		else
		{
			JOptionPane.showMessageDialog(null, "=====================\n" + name + "'s HP: " + herohp + "\n Demon HP: " + bosshp + "\n=====================");
		}
	}
}
